# -*- coding: utf-8 -*-

import time

class serial():
    """ A class for resistors in series """
    def __init__(self):
        self.res_list = []

    def add(self, value):
        """ Adds a resistor to the network """
        if "." in str(value):
            self.res_list.append( str(value) )
        else:
            self.res_list.append( str(value) + ".0" )
        print self.res_list

    def remove(self, value):
        """ Removes a resistor value from the network, if it exists """
        try:
            if ".0" in str(value):
                self.res_list.remove( str(value) )
            else:
                self.res_list.remove( str(value) + ".0" )
        except ValueError:
            print "ValueError called on list. Does the resistor value you gave exist?"
        except:
            print "Some error occured. Check your arguments."
        print self.res_list

    def show(self):
        print "The resistor network is currently:"
        print "Serial"
        for x in self.res_list:
            print str(x) + "Ω",

    def calculate(self):
        print "Calculating Rt"
        time.sleep(1)
        string = ""
        for x in self.res_list:
            string = string + " " + x + " +"
        string = string[1:-1]
        print "Rt = " + string
        time.sleep(1)
        print "Rt = " + str(eval(string)) + "Ω"


class parallel():
    """ A class for resistors in parallel """
    def __init__(self):
        self.res_list = []

    def add(self, value):
        """ Adds a resistor to the network """
        if "." in str(value):
            self.res_list.append( str(value) )
        else:
            self.res_list.append( str(value) + ".0" )
        print self.res_list

    def remove(self, value):
        """ Removes a resistor value from the network, if it exists """
        try:
            if ".0" in str(value):
                self.res_list.remove( str(value) )
            else:
                self.res_list.remove( str(value) + ".0" )
        except ValueError:
            print "ValueError called on list. Does the resistor value you gave exist?"
        except:
            print "Some error occured. Check your arguments."
        print self.res_list

    def show(self):
        print "The resistor network is currently:"
        print "Parallel"
        for x in self.res_list:
            print str(x) + "Ω",
    
    def calculate(self):
        print "Calculating Rt"
        time.sleep(1)
        string = ""
        for x in self.res_list:
            string = string + " (1/" + x + ") +"
        string = string[1:-2]
        print "1/Rt = " + string
        time.sleep(1)
        string = "1/( " + string + " )"
        print "Rt = " + string
        time.sleep(1)
        print "Rt = " + str(eval(string)) + "Ω"
